
package cn.imeth.log4j;

import org.apache.log4j.Level;
import org.apache.log4j.Logger;

/**
 * Created by 戴文龙 on 2014/12/23.
 */
public class Log {

    public static String LOGGER_NAME = "iMeth";

    private static Logger log = Logger.getLogger(LOGGER_NAME);

    public static void initNotUseFile(Level level) {
        init("", level, false);
    }

    public static void init(String logFilePath) {
        init(logFilePath, Level.DEBUG, true);
    }

    public static void init(String logFilePath, Level level) {
        init(logFilePath, level, true);
    }

    public static void init(String logFilePath, Level rootLevel, boolean isUseFileAppender) {
        final LogConfigurator logConfigurator = new LogConfigurator();

        logConfigurator.setFileName(logFilePath);
        // Set the root log level
        logConfigurator.setLevel(rootLevel);
        // Set log level of a specific logger
        logConfigurator.setUseFileAppender(isUseFileAppender);
        logConfigurator.configure();
    }

    public static void init(String loggerName, String logFilePath, Level rootLevel,
            boolean isUseFileAppender) {
        LogConfigurator logConfigurator = new LogConfigurator();
        Logger logger = Logger.getLogger(loggerName);

        logConfigurator.setLogger(logger);
        logConfigurator.setFileName(logFilePath);
        // Set the root log level
        logConfigurator.setLevel(rootLevel);
        // Set log level of a specific logger
        logConfigurator.setUseFileAppender(isUseFileAppender);
        logConfigurator.configure();
    }

    public static void i(Object message){
        log.info(message);
    }
    
    public static void i(Object message, Throwable e){
        log.info(message,e);
    }
 
    public static void w(Object message){
        log.warn(message);
    }
    
    public static void w(Object message, Throwable  e){
        log.warn(message, e);
    }
 
    public static void v(Object message){
        log.trace(message);
    }
    
    public static void v(Object message, Throwable  e){
        log.trace(message, e);
    }
    
    public static void e(Object message){
        log.error(message);
    }
    
    public static void e(Object message, Throwable  e){
        log.error(message, e);
    }
    
    public static void d(Object message){
        log.debug(message);
    }
    
    public static void d(Object message, Throwable  e){
        log.debug(message, e);
    }
    
}
